require("../../../utils/function.js");

var e = getApp(), t = require("../../../api.js");

Page({
    data: {
        vehicle_photo:"",
        vehicle_fphoto:"",
        pageType: null,
        fontImage: null,
        backImage: null,
        idCardPhoto: null,
        idCardPhotoTest: !1,
        driverPhoto: null,
        driverPhotoTest: !1,
        positive: "",
        reverse: "",
        idreverse: "",
        idpositive: "",
        drivers: "",
        isChange: !1
    },
    upFontloadFile: function(a) {
        if (!this.data.isChange) {
            a.currentTarget.dataset.type;
            var i = this;
            wx.showLoading(), wx.chooseImage({
                success: function(a) {
                    var s = a.tempFilePaths;
                    wx.uploadFile({
                        url: t.driver.uploadcar,
                        filePath: s[0],
                        name: "file",
                        formData: {
                            access_token: wx.getStorageSync("access_token"),
                            _uniacid: e.siteInfo.uniacid,
                            _acid: e.siteInfo.acid
                        },
                        success: function(e) {
                            wx.hideLoading();
                            var t = JSON.parse(e.data);
                            0 != t.code ? 1 == t.code && (i.setData({
                                vehicle_photo: t.data
                            }), wx.setStorageSync("vehicle_photo", t.data)) : wx.showToast({
                                title: t.msg,
                                icon: "none"
                            });
                        }
                    });
                }
            });
        }
    },
    upBackloadFile: function(a) {
        if (!this.data.isChange) {
            var i = this;
            a.currentTarget.dataset.type;
            wx.chooseImage({
                success: function(a) {
                    var s = a.tempFilePaths;
                    wx.showLoading(), wx.uploadFile({
                        url: t.driver.uploadcar,
                        filePath: s[0],
                        name: "file",
                        formData: {
                            user: "test",
                            access_token: wx.getStorageSync("access_token"),
                            _uniacid: e.siteInfo.uniacid,
                            _acid: e.siteInfo.acid
                        },
                        success: function(e) {
                            if (wx.hideLoading(), 200 == e.statusCode) {
                                var t = JSON.parse(e.data);
                                if (0 == t.code) return void wx.showToast({
                                    title: t.msg,
                                    icon: "none"
                                });
                                1 == t.code && (i.setData({
                                    vehicle_fphoto: t.data
                                }), wx.setStorageSync("vehicle_fphoto", t.data));
                            }
                        }
                    });
                }
            });
        }
    },
    intoPageHandler: function(e) {
        this.data.vehicle_photo && this.data.vehicle_fphoto && (wx.setStorageSync("vehicle_photo", this.data.vehicle_photo), 
        wx.setStorageSync("vehicle_fphoto", this.data.vehicle_fphoto), wx.showToast({
            title: "上传成功",
            success: function() {
                setTimeout(function() {
                    wx.navigateBack({
                        delta: 1
                    });
                }, 1500);
            }
        }));
    },
    onLoad: function(t) {
        t.uid && e.shareCouponsMessage(t.uid), "true" == t.isChange && this.setData({
            isChange: !0
        }), "driverPhoto" == t.type && "" != wx.getStorageSync("driving_license") && this.setData({
            positive: wx.getStorageSync("driving_license").driverfPhoto,
            reverse: wx.getStorageSync("driving_license").driverPhoto
        }), "vehicle_photo" == t.type && ("" != wx.getStorageSync("vehicle_photo") && this.setData({
            vehicle_photo: wx.getStorageSync("vehicle_photo"),
            vehicle_fphoto: wx.getStorageSync("vehicle_fphoto")
        }), console.log("正面正面", this.data.vehicle_photo), console.log("正面正面22", this.data.vehicle_fphoto)), 
        this.setData({
            pageType: t.type
        });
    },
    onShow: function() {
        var e = wx.getStorageSync("vehicle_photo") || "", t = wx.getStorageSync("vehicle_fphoto") || "";
        console.log(e, "------"), this.setData({
            driver: wx.getStorageSync("driver_information"),
            vehicle_photo: e,
            vehicle_fphoto: t
        });
    },
    onShareAppMessage: function() {
        var t = e.shareAppMessage().title, a = e.shareAppMessage().imageUrl, i = e.shareAppMessage().desc, s = e.shareAppMessage().path;
        return console.log(e.shareAppMessage()), {
            title: t,
            imageUrl: a,
            desc: i,
            path: s
        };
    }
});